package com.object;

import com.Inter.ToJson_;
import com.alibaba.fastjson.JSON;
import com.object.JSON.Body;
import com.object.JSON.SrcInfo;

import java.util.ArrayList;
import java.util.List;

public class toJson implements ToJson_ {
    @Override
    public String ToJson(String path) {
        // 1.读取文件，得到Objets和StreamID
        Get_File gf = new Get_File();
        gf.Get_File(path);
        List<String> objects = gf.objects;
        String streamID = gf.StreamID;
        // 2.替换地址
        new Exchange().Exchange_Internet(objects);
        // 3.获得时间
        DateTime NOW= new DateTime();
        String localtime = NOW.localtime();
        String endtime = NOW.endtime();
        int durationhour = NOW.durationhour();
        String Name = localtime+streamID;

        // SrcInfo
        ArrayList<SrcInfo> list_Src = new ArrayList<SrcInfo>();
        // Body
        ArrayList<Body> bodies = new ArrayList<Body>();

        // 添加SrcInfo元素
        for (int i = 0; i <objects.size(); i++) {
            list_Src.add(new SrcInfo(objects.get(i),i));
        }
        bodies.add(new Body(Name,endtime,"fstv","xmtott.fstvgo.com","live","live_test",streamID+"_01",list_Src,durationhour));
        //System.out.println(bodies);
        String s = JSON.toJSONString(bodies.get(0));
        //System.out.println(s);
        if (s!=null){
            return s;
        }else
        {
            System.out.println("参数错误");
        }
        return null;
    }
}
